package com.zhoutao.blog.seven.model;

import lombok.Data;

import java.util.List;

/**
 * 分页数据集
 */
@Data
public class PageList<T> {

    private boolean hasPre;

    private boolean hasNext;

    private String nextPage;

    private String prePage;

    private List<T> data;

    private long current;

    private long total;

    private long totalPage;

    public static <T> PageList<T> create(List<T> dataPage, long page, long limit, long total) {
        PageList<T> list = new PageList<>();
        list.setData(dataPage);
        list.setCurrent(page);
        list.setTotal(total);
        list.setTotalPage((int) Math.ceil(total * 1.0 / limit));
        list.setHasNext(page < list.getTotalPage());
        list.setHasPre(page > 1);
        return list;
    }
}
